/*
Miranda IM History Sweeper plugin
Copyright (C) 2002-2003  Sergey V. Gershovich
Copyright (C) 2006-2007  borkra

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include "historysweeper.h"

int RebuildContactMenu(WPARAM wParam,LPARAM lParam)
{
	CLISTMENUITEM cli = {0}; 
	char menu_title[255];

	int count = CallService(MS_DB_EVENT_GETCOUNT, wParam, 0); 
	
	if (count != 0)
	{
		wsprintf(menu_title, Translate("Sweep history [%d]"), count);
		cli.flags = CMIM_NAME;
		cli.pszName = menu_title;
	} 
	else 
		cli.flags = CMIF_HIDDEN;

	cli.flags |= CMIM_FLAGS;
	cli.cbSize = sizeof(cli);

	CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hContactMenuHandle, (LPARAM)&cli);

	return 0;
}

void ModifyMainMenu(void)
{
	CLISTMENUITEM mi = {0};
	
	mi.cbSize  = sizeof(mi);
	mi.flags   = CMIM_NAME;
	mi.pszName = Translate(menu_items[DBGetContactSettingByte(0, ModuleName, "MainMenuAction", 0)]);
	
	CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMainMenuHandle, (LPARAM)&mi);
}
void MenuInit (void)
	{
		CLISTMENUITEM mi = {0};
		mi.cbSize = sizeof(mi);
		mi.flags = CMIF_ICONFROMICOLIB;
		mi.icolibItem = GetIconHandle(IDI_MAINICON);

		//add contact menu
		mi.position = 1000099000;
		mi.pszName = Translate("Sweep history");
		mi.pszService = MS_HS_SWEEPCONTACTHISTORY;
		if (DBGetContactSettingByte(NULL, ModuleName, "ContactMenuIcon", 1))
			hContactMenuHandle = (HMENU)CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM)&mi);

		//add main menu item
		mi.position = 500070000;
		mi.pszName = Translate(menu_items[DBGetContactSettingByte(NULL, ModuleName, "MainMenuAction", 0)]);
		mi.pszService = MS_HS_SWEEPHISTORYFROMMAINMENU;
		if (DBGetContactSettingByte(NULL, ModuleName, "MainMenuIcon", 1))
			hMainMenuHandle = (HMENU)CallService(MS_CLIST_ADDMAINMENUITEM, 0, (LPARAM)&mi);
}
